package com.example.controller;

import com.example.pojo.Note;
import com.example.pojo.PageBean;
import com.example.pojo.Result;
import com.example.service.NoteService;
import com.example.service.UserService;
import com.example.util.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.net.URI;
import java.time.LocalDate;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/notes")
public class NoteController {
    @Autowired
    NoteService noteService;


    /**
     * 分页查询有条件
     * @param page 第几页
     * @param pagesize 一页几条数据
     * @return
     */
    @GetMapping
    public Result list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pagesize,
                       @RequestParam (defaultValue = "0") Integer type,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startTime,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime,
                       String title) {
        log.info("分页带条件查询所有笔记");
        PageBean pageBean=noteService.pagelist(page,pagesize,type,startTime,endTime,title);
        return Result.success(pageBean);
    }


    /**
     * 批量删除
     */
    @DeleteMapping("{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("批量删除笔记");
        noteService.delete(ids);
        return Result.success();
    }



}
